from selenium.webdriver.common.by import By
from Page.Page import Page
import time

class Page1(Page):
    # 定位器
    # 请登录定位元素
    login_loc = By.XPATH, '/html/body/div[2]/div/div[1]/div/a[1]'
    # 账号定位
    username_loc = By.ID, 'userName'
    # 密码定位
    password_loc = By.NAME, '_pwd'
    # 登录按钮定位
    login_btn_loc = By.XPATH, '//input[@id="save" and @name="bi_Usuallogin"]'
    # 确认按钮定位
    sure_loc = By.CLASS_NAME, 'bindSub'
    # 选择商品定位
    sp_show_loc = By.XPATH,'//*[@id="crazySale"]/div[1]/div[2]/div[1]/ul/li[5]/div[2]/a'
    # 商品数量定位
    sp_num_loc = By.ID,'_nub'
    # 加入购物车定位
    add_card_loc = By.ID,'addToCartForDetail'

    # 封装定位方法
    # 点击请登录
    def login(self):
        self.click(self.login_loc)

    # 输入账号密码
    def username1(self,username):
        self.send_keys(self.username_loc,username)

    def password1(self,password):
        self.send_keys(self.password_loc,password)

    # 点击登录按钮
    def login_btn(self):
        self.click(self.login_btn_loc)

    # 点击确认按钮
    def sure(self):
        self.click(self.sure_loc)

    # 选择商品
    def sp_show(self):
        self.click(self.sp_show_loc)

    # 清除商品数量文本
    def clear_num(self):
        self.clear(self.sp_num_loc)

    # 输入商品数量：5
    def sp_num(self,sp_num):
        self.send_keys(self.sp_num_loc,sp_num)

    # 点击加入购物车
    def add_card(self):
        self.click(self.add_card_loc)

    # 业务逻辑
    # def test_luojipage1(self):
    #     self.login()
    #     self.username()
    #     self.password()
    #     time.sleep(5)
    #     self.login_btn()
    #     self.sure()
    #     self.sp_show()
    #     self.clear_num()
    #     self.sp_num()
    #     self.add_card()
